package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.ann.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);
    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> selectPage(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查询
     * @param id
     * @return
     * */
    @Select("select * from setmeal where id=#{id}")
    Setmeal selectId(Long id);

    /**
     * 修改套餐表
     * @param setmeal
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 批量删除
     * @param ids
     */
    void delete(List<Long> ids);

    /**
     * 根据套餐id查询包含的菜品列表
     * @param setmealId
     * @return
     */
    @Select("select dish.*,setmeal_dish.copies from dish left join setmeal_dish on dish.id = setmeal_dish.dish_id where setmeal_id=#{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    /**
     * 根据分类id查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据id查询
     * @param setmealId
     * @return
     */
    @Select("select * from setmeal where id=#{setmealId}")
    Setmeal getById(Long setmealId);

    /**
     * 查询套餐总览
     * @param i
     * @return
     */
    @Select("select count(id) from setmeal where status = #{status}")
    Integer getStatus(int i);
}
